package com.cy.detectsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cy.detectsys.entity.ProbeResultConnectCloud;
import com.cy.detectsys.entity.TargetAssets;
import com.cy.detectsys.entity.vo.TargetAssetsVo;
import com.cy.detectsys.service.TargetAssetsService;
import com.cy.detectsys.mapper.TargetAssetsMapper;
import com.cy.detectsys.util.BaseResponseInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author asus
* @description 针对表【target_assets(原数据库 es_fofa 表)】的数据库操作Service实现
* @createDate 2024-06-14 10:57:03
*/
@Service
public class TargetAssetsServiceImpl extends ServiceImpl<TargetAssetsMapper, TargetAssets>
    implements TargetAssetsService{


    @Override
    public BaseResponseInfo targetAssets(TargetAssetsVo targetAssetsVo) {
        List<TargetAssets> list;
        PageInfo<TargetAssets> targetAssets;
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();

        if (targetAssetsVo.getPageNum() != null && targetAssetsVo.getPageSize() != null) {
            // 分页查询
            PageHelper.startPage(targetAssetsVo.getPageNum(), targetAssetsVo.getPageSize());
            QueryWrapper<TargetAssets> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(targetAssetsVo.getKyEdFofaIp())){
                 wrapper.eq("ky_ed_fofa_ip",targetAssetsVo.getKyEdFofaIp());
             }
            if (StringUtils.isNotBlank(targetAssetsVo.getKyEdFofaPort())){
                wrapper.eq("ky_ed_fofa_port",targetAssetsVo.getKyEdFofaPort());
            }
            if (StringUtils.isNotBlank(targetAssetsVo.getKyEdFofaProduct2())){
                wrapper.eq("ky_ed_fofa_product2",targetAssetsVo.getKyEdFofaProduct2());
            }

            list = list(wrapper);
            targetAssets = new PageInfo<>(list);
            baseResponseInfo.data = targetAssets;
        } else {
            // 不传分页参数时直接查询列表
            baseResponseInfo.data = list();
        }
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");
        return baseResponseInfo;
    }

    @Override
    public BaseResponseInfo targetAssetsBox() {

        QueryWrapper<TargetAssets> portWrapper = new QueryWrapper<>();
        portWrapper.select("DISTINCT ky_ed_fofa_port");
        List<TargetAssets> portList = list(portWrapper);

        Map<String, List<TargetAssets>> map = new HashMap<>();
        map.put("portList", portList);

        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        baseResponseInfo.data = map;
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");
        return baseResponseInfo;
    }
}




